package com.qdevelop.model.utils;

import javax.servlet.http.Cookie;

import org.apache.struts2.ServletActionContext;

public class CookieUtils {
	public static void setCookie(String key,String value){
		setCookie(key,value,60*60*24*365);
	}
	public static void setCookie(String key,String value,int age){
		Cookie co = new Cookie(key,value);
		co.setMaxAge(age);
		co.setPath("/");
		ServletActionContext.getResponse().addCookie(co);
	}
	
	public static String getCookie(String key){
		Cookie cookies[] = ServletActionContext.getRequest().getCookies();
		if(cookies.length==0)return null;
		for(Cookie co : cookies){
			if(co.getName().equals(key)){
				return co.getValue();
			}
		}
		return null;
	}

}
